FIND_PACKAGE(PythonInterp REQUIRED)

SET(SOURCES_PY
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/__init__.py
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/image.py
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/region.py
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/internal.py
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/server.py
  ${CMAKE_CURRENT_SOURCE_DIR}/trax/client.py)
SET(BUILD_PYTHON_DIR "${CMAKE_BINARY_DIR}/python")

# Override library prefix on Windows
IF (WIN32)
  set(TRAX_FILENAME trax${CMAKE_SHARED_LIBRARY_SUFFIX})
ELSE()
  set(TRAX_FILENAME ${CMAKE_SHARED_LIBRARY_PREFIX}trax${CMAKE_SHARED_LIBRARY_SUFFIX})
ENDIF()

FILE(MAKE_DIRECTORY ${BUILD_PYTHON_DIR}/trax)

ADD_CUSTOM_COMMAND(OUTPUT
        ${BUILD_PYTHON_DIR}/trax/${TRAX_FILENAME}
    COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:trax>
        ${BUILD_PYTHON_DIR}/trax/${TRAX_FILENAME}
    DEPENDS trax
)

ADD_CUSTOM_TARGET(copy_library_python ALL
#    DEPENDS ${BUILD_PYTHON_DIR}/trax/${TRAX_FILENAME}
)

ADD_CUSTOM_COMMAND(TARGET copy_library_python COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/setup.py ${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/VERSION ${BUILD_PYTHON_DIR}/)
ADD_CUSTOM_COMMAND(TARGET copy_library_python COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SOURCES_PY} ${BUILD_PYTHON_DIR}/trax)
ADD_CUSTOM_COMMAND(TARGET copy_library_python COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TRAX_SOURCE} ${TRAX_HEADERS} ${BUILD_PYTHON_DIR}/trax)
